package com.hualian.dance.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hualian.dance.mapper.DanceMapper;
import com.hualian.system.common.Constants;
import com.hualian.user.mapper.UserMapper;

@Service
public class DanceService {

	@Autowired
	private DanceMapper danceMapper;

	/**
	 * 新建活动
	 * 
	 * @param param
	 * @return
	 */
	public int addActivity(Map<String, Object> params) {
		return danceMapper.addActivity(params);
	}

	/**
	 * 更新活动
	 * 
	 * @param params
	 * @return
	 */
	public int updateActivity(Map<String, Object> params) {
		return danceMapper.updateActivity(params);
	}
	
	
	/**
	 * 删除活动
	 * 
	 * @param params
	 * @return
	 */
	public int removeActivity(int [] ids) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("ids",ids);
		return danceMapper.removeActivity(params);
	}
	

	/**
	 * 查询活动
	 * 
	 * @param params
	 * @return
	 */
	public List<Map<String, Object>> getActivity(Map<String, Object> params) {
		return danceMapper.getActivity(params);
	}
	/**
	 * 查询活动条目
	 * 
	 * @param params
	 * @return
	 */
	public int getActivityCount(Map<String, Object> params) {
		return danceMapper.getActivityCount(params);
	}
	/**
	 * 查询活动明细条目
	 * 
	 * @param params
	 * @return
	 */
	public int getActivityDetailCount(Map<String, Object> params) {
		return danceMapper.getActivityDetailCount(params);
	}
	

	
	

	/**
	 * 新建活动明细
	 * 
	 * @param params
	 * @return
	 */
	public int addActivityDetail(Map<String, Object> params) {
		return danceMapper.addActivityDetail(params);
	}

	/**
	 * 修改活动明细
	 * 
	 * @param params
	 * @return
	 */
	public int updateActivityDetail(Map<String, Object> params) {
		return danceMapper.updateActivityDetail(params);
	}

	/**
	 * 查询活动明细
	 * 
	 * @param params
	 * @return
	 */
	public List<Map<String, Object>> getActivityDetail(Map<String, Object> params) {
		return danceMapper.getActivityDetail(params);
	}
	/**
	 * 删除活动明细
	 * @param ids
	 * @return
	 */
	public int removeActivityDetail(int [] ids) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("ids",ids);
		return danceMapper.removeActivityDetail(params);
	}

	/**
	 * 新建活动分组
	 * 
	 * @param params
	 * @return
	 */
	public int addActivityGroup(Map<String, Object> params) {
		return danceMapper.addActivityGroup(params);
	}

	/**
	 * 更新活动分组
	 * 
	 * @param params
	 * @return
	 */
	public int updateActivityGroup(Map<String, Object> params) {
		return danceMapper.updateActivityGroup(params);
	}

	/**
	 * 查询活动分组
	 * 
	 * @param params
	 * @return
	 */
	public List<Map<String, Object>> getActivityGroup(Map<String, Object> params) {
		return danceMapper.getActivityGroup(params);
	}
	/**
	 * 查询队伍报名
	 * @param params
	 * @return
	 */
	public List<Map<String, Object>> getActivityApply(Map<String, Object> params) {
		return danceMapper.getActivityApply(params);
	}
	/**
	 * 查询活动报名数目
	 * @param params
	 * @return
	 */
	public int getActivityApplyCount(Map<String, Object> params){
		return danceMapper.getActivityApplyCount(params);
	}
	/**
	 * 新增活动报名
	 * @param params
	 * @return
	 */
	public int addActivityApply(Map<String, Object> params) {
		//初始状态未审核
		params.put("status",Constants.APPLY_SOON);
		return danceMapper.addActivityApply(params);
	}
	
	/**
	 * 编辑活动报名
	 * @param params
	 * @return
	 */
	public int updateActivityApply(Map<String, Object> params) {
		return danceMapper.updateActivityApply(params);
	}
	/**
	 * 删除活动报名
	 * @param ids
	 * @return
	 */
	public int removeActivityApply(int [] ids) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("ids",ids);
		return danceMapper.removeActivityApply(params);
	}
	/**
	 * 审核活动报名
	 * @param ids
	 * @return
	 */
	public int applyActivity(int [] ids) {
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, Object> idParams = new HashMap<String, Object>();
		params.put("ids",ids);
		for(int i=0;i<ids.length;i++){
			int id = ids[i];
			idParams.put("id", id);
			Map<String, Object> applys = danceMapper.getActivityApplyById(idParams);
			int insert = danceMapper.addActivityQualification(applys);
			if(insert != 1){
				//插入数据失败
				return 0;
			}
		}
		return danceMapper.applyActivity(params);
	}
	/**
	 * 驳回活动报名
	 * @param ids
	 * @return
	 */
	public int rejectActivity(int [] ids) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("ids",ids);
		return danceMapper.rejectActivity(params);
	}

}
